package org.water.base.support;

import java.util.Iterator;
import java.util.Map;

import javax.persistence.Query;
/**
 * sql 辅助工具类
 * @author qzy
 *
 */
public class SqlHelper {

	/**
	 * query 键值对传值 
	 * @param query
	 * @param params
	 */
	public static void buildQueryParams(Query query, Map<String, Object> params){
		if(null != params){
			Iterator<String> iterator= params.keySet().iterator();
			while (iterator.hasNext()) {
				String key = iterator.next();
				query.setParameter(key, params.get(key));
			}
		}
	}
	/**
	 * query 顺序传值 
	 * @param query
	 * @param params
	 */
	public static void buildQueryParams(Query query, Object[] params){
		if(null != params){
			for (int i = 0; i < params.length; i++) {
				query.setParameter(i+1, params[i]);
			}
		}
	}
}
